// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import Vuex from 'vuex'
import App from './App'
import router from './router'
import store from './store'

import {
  ToastPlugin
} from 'vux' //弹框功能
import "../static/js/commen.js"
Vue.use(ToastPlugin, {
  position: 'middle'
})
Vue.use(router)
Vue.config.productionTip = false
// Vue.prototype.setCookie("accesskey","422d336c8c1045b9b55dc15a2e7ff005")
if(Vue.prototype.getCookie("accesskey")=='422d336c8c1045b9b55dc15a2e7ff005'){
  Vue.prototype.setCookie("accesskey",null)
}
// console.log(Vue.prototype.getCookie("accesskey"))
//页面加载时跳转微信获取accesskey
var key = Vue.prototype.getCookie("accesskey")
// =='null'
// alert(Vue.prototype.getCookie("accesskey")=='undefined')
if (!key || Vue.prototype.getCookie("accesskey")=='null' || Vue.prototype.getCookie("accesskey")=='undefined') {
  if (GetQueryString("state") == "login") {
    Vue.prototype.$ajax.post(Vue.prototype.commenPath + "/vote/vote/login/" + GetQueryString("code"))
      .then(function (res) {
        if (res.data.code == 0) {
          var data1111 = res.data.data
          Vue.prototype.setCookie("accesskey", data1111)
          fun();
        } else {
          alert(data.message + "请关闭页面重新打开")
        }
      })
    .catch(function (res) {})
  } else {
    window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx031005fc43335c2b&redirect_uri=" + window.location.href + "&response_type=code&scope=snsapi_base&state=login#wechat_redirect"
  }
} else {
  fun();
}

Vue.prototype.$ajax.post("http://vote.wabei.cn/vote/sign/url",window.location.href)
  .then(function (res) {
    var data = res.data
    if (data.code == 0) {
      //微信分享功能
      var wxShare = new WxShare({
        share_title: "2022北交所·新三板年终评选正在进行-挖贝网",
        share_url: window.location.href,
        share_desc: "2022北交所·新三板年终评选正在进行，阁下的一票很重要！",
        share_imgurl: "http://files.wabei.cn/img/logo.png",
        appId: "wx031005fc43335c2b",
        timestamp: "1414587457",
        nonceStr: "psKNy1oqeud0v",
        signature: data.data
      });
      wxShare.init();
    }
  })
  .catch(function (res) {

  })

//获取url参数的值
function GetQueryString(name) {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  var r = window.location.search.substr(1).match(reg);
  if (r != null) return unescape(r[2]);
  return null;
}
//微信分享功能
function fun() {
  //   var url =  "http://vote.wabei.cn/index.html";

  if (window.location.href.indexOf("?") != -1) {
    window.location.href = window.location.href.split("?")[0]
  } else {
    new WxShare() //微信分享
  }
}

function WxShare(obj) {
  this.config = function () {
    wx.config({
      debug: false,
      appId: obj.appId,
      timestamp: obj.timestamp,
      nonceStr: obj.nonceStr,
      signature: obj.signature,
      jsApiList: ["onMenuShareAppMessage",
        "onMenuShareTimeline",
        "onMenuShareQQ",
        "onMenuShareWeibo",
        "hideOptionMenu",
        "showOptionMenu",
        "hideMenuItems",
        "showMenuItems",
        "hideAllNonBaseMenuItem",
        "showAllNonBaseMenuItem"
      ]
    });
    wx.ready(function () {
      wx.onMenuShareTimeline({
        title: obj.share_title,
        link: obj.share_url,
        imgUrl: obj.share_imgurl,
        desc: obj.share_desc,
        success: function () {},
        cancel: function () {}
      });
      wx.onMenuShareAppMessage({
        title: obj.share_title,
        link: obj.share_url,
        imgUrl: obj.share_imgurl,
        desc: obj.share_desc,
        type: "",
        dataUrl: "",
        success: function () {},
        cancel: function () {}
      });
      wx.onMenuShareQQ({
        title: obj.share_title,
        link: obj.share_url,
        imgUrl: obj.share_imgurl,
        desc: obj.share_desc,
        success: function () {},
        cancel: function () {}
      });
      wx.onMenuShareWeibo({
        title: obj.share_title,
        link: obj.share_url,
        imgUrl: obj.share_imgurl,
        desc: obj.share_desc,
        success: function () {},
        cancel: function () {}
      });
      wx.onMenuShareQZone({
        title: obj.share_title,
        link: obj.share_url,
        imgUrl: obj.share_imgurl,
        desc: obj.share_desc,
        success: function () {},
        cancel: function () {}
      });
    });
  };
}
WxShare.prototype.init = function () {
  this.config();
};
//防止出现[WDS] Disconnected!警告
if (module.hot) {
  module.hot.accept();
}
new Vue({
  el: '#app',
  router,
  components: {
    App
  },
  store,
  template: '<App/>'
})
